from .handle import handle

activityList = {
        "activity_id": 0,
        "activity_title": "全民种动园",  # 标题
        "activity_count": 20,  # 预设参加人数
        "status": 0,  # 状态
        "imagesSlider": [
            "./resizeimg/6.jpg",
            "./resizeimg/7.jpg",
            "./resizeimg/8.jpg",
        ],  # 轮播图
        "defaultImgIndex": 1,  # 默认图片索引（取轮播图）
        "activity_signed": 12,  # 已参加人数
        "price": 59.6,  # 价格
        "activity_unit": "元/人",  # 单位
        "activity_start_date": "2020-07-20",  # 活动开始时间
        "activity_end_date": "2020-08-20",  # 活动结束时间
        "sign_start_date": "2020-07-13",  # 报名开始时间
        "sign_end_date": "2020-07-28",  # 报名结束时间
        "service_tel": "0721-8392580",   # 咨询电话
        "address": "测试",  # 地址
        "activity_content": "虽然做了一件好事，但很有可能因此招来他人的无端猜测，例如被质疑是否藏有其他利己动机等，乃至谴责。即便如此，还是要做好事。",#介绍
        "imageContent": [
            "./resizeimg/5.jpg",
            "./resizeimg/4.jpg",
            "./resizeimg/3.jpg",
            "./resizeimg/1.jpg",
            "./resizeimg/2.jpg",
        ],  # 图片详情
}

class activityHandle(handle):
    def __init__(self):
        super(activityHandle, self).__init__()

    def updateActivity(self, data):
        sliderimg_paths = data["imagesSlider"]
        contentimg_paths = data["imageContent"]
        temp = sliderimg_paths + contentimg_paths
        files = self._getFile(temp)

        del data["imagesSlider"]
        del data["imageContent"]
        data["sliderCount"] = sliderimg_paths.__len__()
        data["contentCount"] = contentimg_paths.__len__()
        url = self._base_url + "upload_activity"

        return self._handle(url=url, data=data, files=files)

    def activity_sout_out(self, goods_id):
        data = {
            "activity_id": goods_id
        }
        url = self._base_url + "activity_sold_out"

        return self._handle(url=url, data=data)

    def activity_del(self, goods_id):
        data = {
            "activity_id": goods_id
        }
        url = self._base_url + "activity_del"

        return self._handle(url=url, data=data)

    def activity_show(self):
        url = self._base_url + "activity_show"

        return self._handle(url=url, htype="GET")


def main():
    activityhandler = activityHandle()
    #res = activityhandler.updateActivity(activityList)
    #res = activityhandler.activity_sout_out(1)
    #res = activityhandler.activity_del(1)
    res = activityhandler.activity_show()
    print(res["activityList"].__len__())
    #print(res["activityList"][0]["imageContent"].__len__())
    #img = cv2.imdecode(np.fromstring(b64decode(res["goodsList"][0]["imageContent"][4]), np.uint8), 1)
    #cv2.imshow("", img)
    #cv2.waitKey(0)
    print(res)

if __name__ == "__main__":
    main()
